package main

import (
	"flag"
	"fmt"
	"log"
	"os"
)

func printUsage()  {

	fmt.Println("Usage:")
	fmt.Println("\taddblock -data DATA -- 交易数据.")
	fmt.Println("\tprintchain -- 输出区块信息.")

}

func isValidArgs()  {
	if len(os.Args) < 2 {
		printUsage()
		os.Exit(1)
	}
}


func main() {

	addBlockCmd := flag.NewFlagSet("addBlock",flag.ExitOnError)
	printChainCmd := flag.NewFlagSet("printchain",flag.ExitOnError)


	flagAddBlockDData := addBlockCmd.String("data","默认值","交易数据....")

	switch os.Args[1] {
	case "addBlock":
		err := addBlockCmd.Parse(os.Args[2:])
		if err != nil {
			log.Panic(err)
		}

	case "printchain":
		err := printChainCmd.Parse(os.Args[2:])
		if err != nil {
			log.Panic(err)
		}
	default:
		printUsage()
		os.Exit(1)
	}

	if addBlockCmd.Parsed() {
		if *flagAddBlockDData == ""{
			printUsage()
			os.Exit(1)
		}
		fmt.Println(*flagAddBlockDData)
	}

	if printChainCmd.Parsed() {

		fmt.Println("输出所有区块的数据........")

	}

}
